# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer:
pkgname=distrobuilder
pkgver=0_git20181004
_commit=d2329be9569d45028a38836186d2353b8ddfe1ca
pkgrel=2
pkgdesc="System container image builder"
url="https://linuxcontainers.org/"
arch="" # Build fails on the builders
license="Apache-2.0"
depends="gnupg1"
makedepends="go linux-headers glide"
subpackages="$pkgname-lxc::noarch $pkgname-lxd::noarch"
options="!check" # has no check
source="$pkgname-$pkgver.tar.gz::https://github.com/lxc/distrobuilder/archive/$_commit.tar.gz
	glide-$pkgver.yaml
	glide-$pkgver.lock
	"
builddir="$srcdir/src/github.com/lxc/$pkgname"

prepare() {
	mkdir -p ${builddir%/*}
	mv "$srcdir"/$pkgname-$_commit "$builddir"/
	cp "$srcdir"/glide-$pkgver.yaml glide.yaml
	cp "$srcdir"/glide-$pkgver.lock glide.lock
	export GLIDE_HOME="$srcdir/.glide"
	export GOPATH="$srcdir"
	glide install --skip-test
	default_prepare
}

glide_init() {
	abuild clean deps unpack prepare
	cd "$builddir"
	export GLIDE_HOME="$srcdir/.glide"
	export GOPATH="$srcdir"
	rm -f glide.yaml glide.lock
	glide init --non-interactive
	glide update
	cp glide.yaml "$startdir"/glide-$pkgver.yaml
	cp glide.lock "$startdir"/glide-$pkgver.lock
	cd "$startdir" && abuild checksum clean
}

build() {
	export GOPATH="$srcdir"
	go build -o bin/$pkgname ./$pkgname
}

package() {
	install -Dm755 bin/$pkgname "$pkgdir"/usr/bin/$pkgname
}

lxc() {
	pkgdesc="$pkgdesc (for LXC)"
	depends="$pkgname"
	install_if="$pkgname=$pkgver-r$pkgrel lxc"
	mkdir -p "$subpkgdir"
}

lxd() {
	pkgdesc="$pkgdesc (for LXD)"
	depends="$pkgname squashfs-tools"
	install_if="$pkgname=$pkgver-r$pkgrel lxd"
	mkdir -p "$subpkgdir"
}

sha512sums="de50479ab6de5bca80c48ca14ae29ad712a5c6ac1ec7661d28da5b42c77ef0bbc4c00f95080abad2838663c3cf015466c2e2d1ba75168a440df18dfebc2bc0a5  distrobuilder-0_git20181004.tar.gz
602a97b07d6c0b0eca1cec26e3b66223cf0148842ccef429de273d77be2d91c24d98732977fc42b1f068f6f08807faebb061607bf27384bc1555daa8137d235f  glide-0_git20181004.yaml
1d941f26aaaebff4bccf6bc50688cd38f315e819f0521a1a0fa43acca00173c561376dd5ef7d2bf42d0fe03a016a5bb303e7c42786b847033215ebb2d74e5ba7  glide-0_git20181004.lock"
